// pages/list.js
const product = require('../../utils/product.js')
var app = getApp()
Page({
  data: {
    sii: 1,
    primarySize: 'default',
    radioItems: [
      { name: '支付1000元订金享95折￥1000', value: '1000', checked: 'true' },
      { name: '支付2000元订金享85折￥2000', value: '2000' },
    ],
  },

  onLoad: function (obj) {
    var that = this
    product.getlist(obj.cat_title, function (resolve) {
      var data = resolve.data;
      console.log("list", data);
      var list = data.price_int           //运用split分割数据，取到想要的数据
       var detail2 = list.split(",")
        console.log("list8888888888", detail2);
       var Dprice= []
       var Dprice_1 =[]
       var earnest =[]
       Dprice = detail2[0].split("￥")
       Dprice_1 = detail2[1].split("￥")
       earnest[0] =Dprice[1]
       earnest[1] =Dprice_1[1]
       console.log("list66666", earnest);
       console.log("list9999999", Dprice_1);
       that.setData({ 'item': data })
       that.setData({'detail2': detail2})
       that.setData({'earnest': earnest})
      wx.setStorage({ key: "earnest", data: earnest})
      wx.setStorage({ key: "list", data: detail2})
      wx.setStorage({
        key: "detail",
        data: data
      })
    })
  },
  add: function (e) {
    var that = this
    var sumsii = ++that.data.sii
    this.setData({
      sii: sumsii
    })
  },

  min: function (e) {
    var that = this
    var sumsii = --that.data.sii
    if (sumsii == 0) {
      sumsii = 1
    }
    this.setData({
      sii: sumsii
    })
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    getApp().data.info =e.detail.value
    console.log('全局携带数据为：', getApp().data.info)
    wx.navigateTo({
      url: `../Info/info?id=${e.detail.value.id}`
    })
  },


  radioChange: function (e) {
    var checked = e.detail.value
    var changed = {}
    for (var i = 0; i < this.data.radioItems.length; i++) {
      if (checked.indexOf(this.data.radioItems[i].name) !== -1) {
        changed['radioItems[' + i + '].checked'] = true
      } else {
        changed['radioItems[' + i + '].checked'] = false
      }
    }
    this.setData(changed)
  }
})